package com.jbh.yxjdemobykontlin

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.widget.Button
import androidx.activity.ComponentActivity
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.google.gson.Gson
import com.jbh.lib_base.RoutePath
import com.jbh.request.AppApi.AppImpl
import com.jbh.request.AppApi.CommonRequest.tag
import com.jbh.request.i.YxjCallback
import com.jbh.request.response.UserInfoResponse
import com.jbh.yxjdemobykontlin.R.layout.demo_layout

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(LayoutInflater.from(this).inflate(demo_layout, null))
        showCounter()
        userInfoTask()
        TimeDateUtil().info()
    }



    private fun showCounter() {
        findViewById<Button>(R.id.btnText).setOnClickListener {
            ARouter.init(this.application)
            ARouter.getInstance().build(RoutePath.Login_Activity)
                .navigation(this, object : NavigationCallback {
                    override fun onFound(postcard: Postcard?) {
                        // 路由被找到
                        showLog("路由被找到")
                    }

                    override fun onLost(postcard: Postcard?) {
                        // 路由丢失
                        showLog("路由丢失")
                    }

                    override fun onArrival(postcard: Postcard?) {
                        // 路由到达
                        showLog("路由到达")
                    }

                    override fun onInterrupt(postcard: Postcard?) {
                        // 路由被阻拦
                        showLog("路由被阻拦")
                    }
                });
        }
    }

    private fun showLog(msg: String) {
        Log.v("[showLog]->", msg)
    }


    private fun userInfoTask() {
        AppImpl.userInfoTask(object : YxjCallback<UserInfoResponse>() {
            override fun onSuccess(t: UserInfoResponse) {
                Log.v(tag, "userInfoTask->${Gson().toJson(t)}")
            }

            override fun onFailure(code: Int, msg: Any) {
                Log.v(tag, "userInfoTask->${msg}")
            }
        })


        AppImpl.homeNewsListTask(object : YxjCallback<Any>() {

            override fun onSuccess(t: Any) {
                Log.v(tag, "homeNewsListTask->${Gson().toJson(t)}")
            }

            override fun onFailure(code: Int, msg: Any) {
                Log.v(tag, "homeNewsListTask->${msg}")
            }
        })
    }
}




